using System;
using System.Windows;
using System.Windows.Forms;
using Common;
using SExperiment;
using SExperiment.ExperimentResult;

namespace MainView.MainControls.Chart
{
	public class DifferenceCurveChart : BaseHRMCurveChart
	{
		public static readonly RoutedEvent ReferenceCurveWindowOpenEvent = EventManager.RegisterRoutedEvent("ReferenceCurveWindowOpen", RoutingStrategy.Bubble, typeof(EventHandler<RoutedEventArgs>), typeof(DifferenceCurveChart));

		public event RoutedEventHandler ReferenceCurveWindowOpen
		{
			add
			{
				AddHandler(ReferenceCurveWindowOpenEvent, value);
			}
			remove
			{
				RemoveHandler(ReferenceCurveWindowOpenEvent, value);
			}
		}

		public DifferenceCurveChart()
		{
			base.Margin = new Thickness(1.0);
			base.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
			base.VerticalAlignment = VerticalAlignment.Stretch;
			SetResourceReference(BaseCurveChart.CaptionProperty, "melting_difference_curve");
			SetResourceReference(BaseCurveChart.TitleXProperty, "Temperature");
			base.TitleY = "%";
			base.MinY = 0.0;
			base.MaxY = 1000.0;
			base.TitleXFormat = "0";
			base.TitleYFormat = "0.000";
		}

		public override string GetToolTipFormatX()
		{
			return "0.00";
		}

		public override Curve GetCurve(SampleTargetItem item)
		{
			if (item.Result is HRMTargetResult)
			{
				return ((HRMTargetResult)item.Result).DifferenceCurve;
			}
			return null;
		}

		protected override void InitMenu()
		{
			base.UltraChart.ContentMenu.Items.Add(new ToolStripSeparator());
			ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
			toolStripMenuItem.Text = Utility.GetMessage("select_reference_curve");
			toolStripMenuItem.Click += Reference_curveClick;
			base.UltraChart.ContentMenu.Items.Add(toolStripMenuItem);
		}

		protected void Reference_curveClick(object sender, EventArgs e)
		{
			RoutedEventArgs routedEventArgs = new RoutedEventArgs();
			routedEventArgs.RoutedEvent = ReferenceCurveWindowOpenEvent;
			RoutedEventArgs e2 = routedEventArgs;
			RaiseEvent(e2);
		}
	}
}
